<?php
require 'page.class.php';
    $connetc=mysql_connect("localhost","root","192510");
	mysql_select_db("news",$connetc);
	$sql2="select count(*) as amount from mygroup";
	$result2=mysql_query($sql2);
	$row2=mysql_fetch_array($result2);
	$count=$row2['amount'];//总条数
	$pagesize=10;//每页显示的条数
	
	if($count%$pagesize){
		$page=ceil($count/$pagesize);
	}else{
		$page=$count/$pagesize;
	}
	
	if(isset($_GET['currentpage'])){
		$currentpage=intval($_GET['currentpage']);
    }else{
		$currentpage=1;
    }
	$start=($currentpage-1)*$pagesize;
    $sql="select * from mygroup limit $start,$pagesize";
    $result = mysql_query($sql);
	
   //得到网站中checkbox中的值
   $sql2="select * from wangzhan";
   $result2=mysql_query($sql2);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-1.6.3.min.js"></script>
<link rel="stylesheet" type="text/css" href="../time/jquery.datetimepicker.css"/>
<script src="../time/jquery.js"></script>
<script src="../time/jquery.datetimepicker.js"></script>
<style>
    .tip{
		width:640px;
		height:750px;
	}
	
	.xdsoft_datetimepicker xdsoft_noselect{
		
		top:40px;
	}
	
</style>
<script type="text/javascript">
$(document).ready(function(){
  $(".click").click(function(){
  $(".tip").fadeIn(200);

  });
  
  $(".tiptop a").click(function(){
  $(".tip").fadeOut(200);
});

  $(".sure").click(function(){
  $(".tip").fadeOut(100);
});

  $(".cancel").click(function(){
  $(".tip").fadeOut(100);
});

});
</script>

</head>

<body>
	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="#">兴趣群管理</a></li>
    <li><a href="#">群列表</a></li>
    </ul>
    </div>
    
    <div class="rightinfo">
	
    <div class="tools">
    	<ul class="toolbar">
        <li onclick="ck(0)"><span><img src="images/t01.png" /></span>添加</li>
        <li onclick="deletebatch()"><span><img src="images/t03.png" /></span>删除</li>
        </ul>
    </div>
	
    <table class="tablelist">
    	<thead>
    	<tr>
        <th><input type="checkbox" onclick="selectAll(this)"/></th>
        <th>群名称</th>
        <th>状态</th>
        <th>基本操作</th>
        </tr>
        </thead>
		
        <tbody>
		<?php
		while($row=mysql_fetch_array($result)){
		?>
		<tr>
        <td><input  type="checkbox" name="son_checkbox" value="<?php echo $row['id'];?>"/></td>
        <td><?php echo $row['name'];?></td>
        <td><?php if($row['check_status']==1){echo "待发送";}if($row['check_status']==2){echo "已发送";}?></td>
        <td><a href="select_shouzhong2.php?gid=<?php echo $row['id'];?>" class="tablelink">添加受众</a> <a onclick="ck('<?php echo $row['id'];?>')" href='#' class="tablelink">修改</a>  <a href="delete_group.php?id=<?php echo $row['id'];?>" class="tablelink"> 删除</a></td>
        </tr> 
		<?php
		}
		?>
		
        </tbody>
		
    </table>
    
    <div class="pagin">
    <?php 
    	pagelinks();
    ?>
    </div>
	
     <div class="tip" style="z-index:1;top:2%;">
     <div class="tiptop"><span>群列表</span><a></a></div>
     <div class="tipinfo">
     <ul class="forminfo">
	 <input size="20" type="hidden" name="id" id="id">
     <li><label>群名称</label><input  type="text" name="name" id="name"  onblur="qun_name();"  class="dfinput"  value="<?php echo $row['name'];?>"/><i  style="margin-right:8px;display:none;" id="yz_qun_name">群名称不能为空</i></li>
     <li><label>推送方式</label><cite><input type="radio" type="radio" name="send_status" id="send_status" value="0" <?php if($row['send_status']==0){echo "checked=checked";}?>/>定时发送 &nbsp;&nbsp;每天<input type="text" id="send_time" name="send_time"/>点发送</cite></li>
	 <li><input type="radio" type="radio" name="send_status" id="send_status" value="1" style="margin-left:85px;" <?php if($row['send_status']==1){echo "checked=checked";}?>/>立即发送</li>
   
     <li><label>邮件标题</label><cite><input type="text" name="email_title" id="email_title"  class="dfinput" value="<?php echo isset($row['email_title'])?$row['email_title']:'云盾新闻中心订阅新闻';?>"/></cite></li>
     <li><label>是否接收空邮箱</label><cite><input type="radio" name="null_email" id="null_email" value="0" <?php if($row['null_email']==0){echo "checked=checked";}?>>是</input>
		                                     <input type="radio" name="null_email" id="null_email" value="1" <?php if($row['null_email']==1){echo "checked=checked";}?>>否</input></cite></li>
     <li><label>发送权限</label><cite>[请用换行符区分关键字的过滤]</cite></li>
     <li><label>标题关键字</label><textarea name="g_title" id="g_title" style="width: 350px;height:40px;overflow-y:visible" name="" cols="" rows="" class="textinput"><?php echo $row['g_title'];?></textarea></li>
	 <li><label>作者关键字</label><textarea name="g_author" id="g_author" style="width: 350px;height:40px;" name="" cols="" rows="" class="textinput"><?php echo $row['g_author'];?></textarea></li>
	 <li><label>来源网站</label>
	 <table style="border-collapse:collapse;border:1px solid gray ; width:400px;heigth:100px;">
	
    <?php
		 while($row2=mysql_fetch_array($result2)){	   
    ?>
		   
		<tr>
	    <td><input type="checkbox" name="g_web" checked="checked" id="g_web<?php echo $row2['id'];?>" value="<?php echo $row2['id'];?>"/></td>
		<td><?php echo $row2['name'];?></td>
		</tr>
		  
    <?php	
		}
    ?>
	    <input type="hidden" id="hiddenid" value="<?php echo isset($row)?$row['id']:'-1'; ?>">
	</table> 
	
	</li>
	<li><label>&nbsp;</label><input name="" type="button" class="btn" onclick="jianqun();" value="确认保存"/>
    </ul>
    </div>
    </div>
    
    
    </div>
    <script type="text/javascript">
	
	$('#send_time').datetimepicker({
		
				minDate:0,

    });
	
	$('.tablelist tbody tr:odd').addClass('odd');
	
	function selectAll(objs){
		
		 var obj=document.getElementsByName('son_checkbox');
		 
		 for(var i=0;i<obj.length;i++){
			 
			 if(objs.checked){
				 obj[i].checked=true;
			 }else{
				 obj[i].checked=false;
			 }
			 
		 }
		 
	}
	
	function deletebatch(){
		
		 obj=document.getElementsByName('son_checkbox');
		 var arrayid=new Array();
		 for(var i=0;i<obj.length;i++){
			 if(obj[i].checked){
				 arrayid.push(obj[i].value);
			 }
			 
		 }
		 
		 if(arrayid.length==0){
			   alert("请选择需要删除的任务");
		 }else{
			
			  if(confirm("确定要删除所选择的用户吗")){
				  $.post('delete_group.php',{arrayid:arrayid},function(data){
				  window.location.reload();
			     });
			  }else{
				  return false;
			  }
			  
	    }
		
	}
	
	
	 function qun_name(){
		var name=$("#name").val();
		if(name==null||name.length==0){
			$("#yz_qun_name").show();
		
		}else{
		
			$("#yz_qun_name").hide();
		
		}
	
    }
   
   function ck(id){
	   if(id==0){  //说明是添加
	      $("#name").val("");
		  $('input:radio[name="send_status"]').get(0).checked=true;
		  $("#send_time").val("");
		  $('input:radio[name="null_email"]').get(0).checked=true;
		  $("#g_title").val("");
		  $("#g_author").val("");
		  $("#id").val("");
		  var g_web=[];
		  $('input[name="g_web"]:checked').each(function(){ 
            g_web.push($(this).val());  
          });
		 for(var i=0;i<g_web.length;i++){
			$("#g_web"+g_web[i]).attr("checked",true);
		  }
		   
	   }else{      //说明是编辑
		  $.post("select_group_id.php",{id:id},function(data){
			    $("#id").val(data['id']);
                $("#name").val(data['name']);
			    $("#email_title").val(data['email_title']);
				var status=data['send_status']; //立即发送还是及时发送
				if(status==0){
					$('input:radio[name="send_status"]').get(0).checked=true;
			     }else{
					 $('input:radio[name="send_status"]').get(1).checked=true;
				 }
				 
				$("#send_time").val(data['send_time']);
				var null_email=data['null_email']; //是否接收空邮箱
				if(null_email==0){
					$('input:radio[name="null_email"]').get(0).checked=true;
			     }else{
					 $('input:radio[name="null_email"]').get(1).checked=true;
				 }
				 
				 $("#g_title").val(data['g_title']);
				 $("#g_author").val(data['g_author']);
				 //回选网站
				 //选择框中的所有的value
				 var g_web=[];
		         $('input[name="g_web"]:checked').each(function(){ 
                   g_web.push($(this).val());  
				 });
				 
				//数据库中需要选中的
				var ss=data['g_web'];
				var array=new Array();
				array = ss.split(',');
				for(var i=0;i<g_web.length;i++){
					$("#g_web"+g_web[i]).attr("checked",false);
		        }
				
			   for(var j=0;j<array.length;j++){
				  $("#g_web"+array[j]).prop("checked",true);
		       }
				
			
			      
		   },"json")
	   }
	     $(".tip").fadeIn(200);
	   
   }
  
	 function jianqun(){
	     
	 	 var name=$("#name").val();
		
		 if(name==null||name.length==0){
			 
			 alert("群名称不能为空");
			 window.location.href="../insert/insert_group.php";
		 }else{
			 
		 var id=$("#id").val();
	     var g_web=[];
	     var email_title=$("#email_title").val();
		 var send_status= $('input:radio[name="send_status"]:checked').val();
		 var send_time=$("#send_time").val();
		 var g_title=$("#g_title").val();
         var g_author=$("#g_author").val();
		 var null_email=$('input:radio[name="null_email"]:checked').val();
		 $('input[name="g_web"]:checked').each(function(){ 
            g_web.push($(this).val());  
         }); 
		 
	  $.post("insert_group_commit.php",
		  { 
		     id:id,
			 name:name,
			 send_status:send_status,
			 send_time:send_time,
			 g_title:g_title,
			 g_author:g_author,
			 g_web:g_web,
			 email_title:email_title,
			 null_email:null_email
		  },
		  function(data){
			  alert("操作成功");
			  window.location.href="select_group.php";
		      // $("#name").val(data.name);
			  // $("send_status").val(data.send_status);
			  // $("#send_time").val(data.send_time);
			  // $("#g_title").val(data.g_title);
			  // $("#g_author").val(data.g_author);
			  // $("#g_web").val(data.g_web);
			  // $("#email_title").val(data.email_title);
			  // $("#gid").val(data.id);
			  // $("#hiddenid").val(data.id);
		 }) 
			 
		 }
	  
	 } 
	
	</script>

</body>

</html>
